﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LotteryBO;


namespace LotteryMgtSystem
{
    public partial class _Default : System.Web.UI.Page
    {
        Lottery lt = new Lottery();
        protected void Page_Load(object sender, EventArgs e)
        {
           if (!IsPostBack)
          {
                DataTable dt = lt.GetRecords(-99, "", "1/1/1800", "1/1/1800", -99, -99, "", false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();
        }
        }

        


        protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DataTable dt = lt.GetRecords(Convert.ToInt64(e.CommandArgument), "", "1/1/1800", "1/1/1800", -99, -99, "", false, " and ");
                lt.lottery_id = Convert.ToInt64(dt.Rows[0]["lottery_id"].ToString());
                lt.company = dt.Rows[0]["company"].ToString();
                lt.lottery_date = dt.Rows[0]["lottery_date"].ToString();
                lt.end_date = dt.Rows[0]["end_date"].ToString();
                lt.total_tickets = Convert.ToInt64(dt.Rows[0]["total_tickets"].ToString());
                lt.initial_amt = Convert.ToInt64(dt.Rows[0]["initial_amt"].ToString());
                lt.winner_id = dt.Rows[0]["winner_id"].ToString();
                lt.isdeleted = true;
                lt.SaveRecords();
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            lt.lottery_id = -99;
            lt.company = TextBox1.Text;
            lt.lottery_date = TextBox2.Text;
            lt.end_date = TextBox3.Text;
            lt.total_tickets = Convert.ToDecimal(TextBox4.Text);
            lt.initial_amt = Convert.ToInt64(TextBox5.Text);
            lt.winner_id = TextBox6.Text;
            lt.isdeleted = false;

            lt.SaveRecords();
            Response.Redirect("~/Default.aspx");

        }
    }
}
